﻿
CREATE PROCEDURE [dbo].[DeleteLogUpdate]
(
	@TableName varchar(50),
	@IdValue int,
	@NotFound bit,
	@Deleted bit,
	@RejectReason varchar(250),
	@Note varchar(250),
	@MD datetime,
	@MW varchar(50),
	@Original_Id int,
	@Original_MD datetime
)
AS
DECLARE @strMsg nvarchar(500), @intRet int, @intErrCode int

	SET NOCOUNT ON

IF (@TableName Is Null) OR (@IdValue Is Null)
BEGIN
	SELECT @intErrCode = 1, @strMsg = 'Неправильные параметры в вызове процедуры ' + Object_Name(@@Procid) + ' !'
	RAISERROR (@strMsg, 11, @intErrCode)
	RETURN @intErrCode
END

EXEC [dbo].[ProcessStatistic] @Note OUTPUT, @MD OUTPUT, @MW OUTPUT
	SET NOCOUNT OFF;
UPDATE [PR].[DeleteLog] SET @TableName = @TableName, @IdValue = @IdValue, 
@NotFound = @NotFound, @Deleted = @Deleted, @RejectReason = @RejectReason,
[Note] = @Note, [MD] = @MD, [MW] = @MW 
WHERE Id = @Original_Id;
	
SELECT [Id],[TableName],[IdValue],[NotFound],[Deleted],[RejectReason],[Note],[MD],[MW]
FROM [PR].[DeleteLog] WHERE (Id = @Original_Id)
RETURN 0
